﻿using MediatR;
using SystemLYH.API.Application.Command.LocationCommand;
using SystemLYH.Infrstructre.Impl;
using SystemLYH.Infrstructre.Interface;

namespace SystemLYH.API.Application.Handlers.LocationHandlers
{
    public class LocationDeleteHandlers : IRequestHandler<LocationDeleteCommand, int>
    {
        protected readonly ILocationRepository _locationRepository;
        /// <summary>
        /// 库位构造函数
        /// </summary>
        /// <param name="locationRepository"></param>
        public LocationDeleteHandlers(ILocationRepository locationRepository)
        {
            _locationRepository = locationRepository;
        }
        public async Task<int> Handle(LocationDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = (await _locationRepository.GetAllAsync()).Where(x => request.LocationId.Contains(x.LocationId)).ToList();
            foreach (var item in list)
            {
                item.IsDelLocation = true;
                await _locationRepository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
